//
//  3PLListCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/8/31.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "TPLListCell.h"

@interface TPLListCell ()

@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *infoLab;
@property (nonatomic, strong) UIButton *editBtn;
@property (nonatomic, strong) UILabel *lineLab;

@end

@implementation TPLListCell

+ (instancetype)TPLListCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"TPLListCell";
    TPLListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[TPLListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = HexColor(0xffffff);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.nameLab = [[UILabel alloc] initWithFrame:CGRectMake(15, 20, ScreenW - 15 - 15 - 64 - 15, 19)];
        self.nameLab.font = BoldFontOfSize(18);
        self.nameLab.textColor = HexColor(0x2B2C44);
        [self.contentView addSubview:self.nameLab];
        
        self.infoLab = [[UILabel alloc] initWithFrame:CGRectMake(self.nameLab.nim_left, self.nameLab.nim_bottom + 8, self.nameLab.nim_width, 15)];
        self.infoLab.font = [UIFont systemFontOfSize:14];
        self.infoLab.textColor = HexColor(0x2B2C44);
        [self.contentView addSubview:self.infoLab];
        
        self.lineLab = [[UILabel alloc] initWithFrame:CGRectMake(15, self.infoLab.nim_bottom + 20, ScreenW - 15, 1)];
        self.lineLab.backgroundColor = Color_backgroundColor;
        [self.contentView addSubview:self.lineLab];
        
        self.editBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenW - 15 - 64, (self.lineLab.nim_top - 30) * 0.5, 64, 30)];
        [self.editBtn setTitle:@"编辑" forState:0];
        [self.editBtn setTitleColor:Color_ThemeColor forState:0];
        self.editBtn.titleLabel.font = BoldFontOfSize(14);
        self.editBtn.backgroundColor = HexColorA(0x3D68EB, 0.1);
        self.editBtn.layer.masksToBounds = YES;
        self.editBtn.layer.cornerRadius = 15;
        [self.editBtn addTarget:self action:@selector(editClick) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.editBtn];
        
        self.height = self.lineLab.nim_bottom;
    }
    return self;
}

- (void)editClick {
    if (self.editBlock) {
        self.editBlock();
    }
}

-(void)setModel:(TPLMainModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.nameLab.text = self.model.tlogistics_name;
    self.infoLab.text = [NSString stringWithFormat:@"%@ / %@",self.model.tl_worker_name,self.model.tl_worker_phone];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
